<template>
	<view class="content mainpadding">
		<view class="mainpadding ffffff border margin_bottom3 flexbetween">
			<view class="titletext xiaohei margin_right3" style="min-width: 150rpx;">身份证号</view>
			<view class="flexright">
				<input class="titletext textright margin_right flex1" style="width: 70%;" type="text" placeholder="请输入身份证号" v-model="idcard">
				<view class="xiaohong main_size" @click="chaxun">查询</view>
			</view>
		</view>
		<!-- 持卡人 -->
		<view class="mainpadding ffffff border margin_bottom3 flexbetween">
			<view class="titletext xiaohei margin_right3">姓名</view>
			<input class="titletext textright flex1" type="text" placeholder="请输入姓名" v-model="name">
		</view>
<view class="mainpadding ffffff border margin_bottom3 flexbetween">
			<view class="titletext xiaohei margin_right3">手机号</view>
			<input class="titletext textright flex1" type="number" placeholder="请输入手机号" v-model="tel">
		</view>
		<view class="mainpadding ffffff border margin_bottom3 flexbetween">
			<view class="titletext xiaohei margin_right3">性别</view>
			<view class="flexright">
				<u-radio-group v-model="sex" placement="row" circle>
					<u-radio activeColor="#c1282e" label="男" :customStyle="{marginRight: '30rpx'}" :name="1"></u-radio>
					<u-radio activeColor="#c1282e" label="女" :name="2"></u-radio>
				</u-radio-group>
			</view>
		</view>
		
		<view class="mainpadding ffffff border margin_bottom3 flexbetween">
			<view class="titletext xiaohei margin_right3">身份居住地</view>
			<input class="titletext textright flex1" type="text" placeholder="请输入身份证居住地" v-model="address">
		</view>
		<view class="mainpadding ffffff border margin_bottom3 flexbetween" @click="gwshow=true">
			<view class="titletext xiaohei margin_right3">岗位</view>
			<view class="flexright">
				<input class="titletext textright flex1" type="text" placeholder="请选择岗位" disabled=""
					v-model="gw_name">
				<u-icon name="arrow-right" color="#999" size="16"></u-icon>
			</view>
		</view>
		<view class="mainpadding ffffff border margin_bottom3 flexbetween" @click="htshow=true">
			<view class="titletext xiaohei margin_right3">合同公司</view>
			<view class="flexright">
				<input class="titletext textright flex1" type="text" placeholder="请选择与员工签合同公司" disabled=""
					v-model="htcompany_name">
				<u-icon name="arrow-right" color="#999" size="16"></u-icon>
			</view>
		</view>
		<view class="mainpadding ffffff border margin_bottom3 flexbetween" @click="yhdhshow=true">
			<view class="titletext xiaohei margin_right3">企业公司</view>
			<view class="flexright">
				<input class="titletext textright flex1" type="text" placeholder="请选择合作项目企业" disabled=""
					v-model="company_name">
				<u-icon name="arrow-right" color="#999" size="16"></u-icon>
			</view>
		</view>
		<view class="mainpadding ffffff border margin_bottom3 flexbetween">
			<view class="titletext xiaohei margin_right3">险种</view>
			<view class="flexright">
				<input class="titletext textright flex1" type="text" placeholder="请选择险种" disabled=""
					v-model="user_gb_xz_name">
				<u-icon name="arrow-right" color="#999" size="16"></u-icon>
			</view>
		</view>
		<view class="submitbtn margin_top6" @click="submit()">
			确认
		</view>
		<view class="posibottom flexcenter mainpadding" @click="checked=checked?false:true">
			<!-- <view class="strongtext xiaohong margin-top">购保须知：{{config.buybxz}}</view> -->
			<uni-icons v-if="!checked" type="circle" size="24"></uni-icons>
			<uni-icons v-else type="checkbox-filled" color="#4A9CE7" size="24"></uni-icons>
			<text>请仔细阅读并勾选</text>
			<text class="colortext" @click.stop="userAgreement(3)">《购保须知》</text>
		</view>
		<u-picker :show="yhdhshow" :columns="yhdhcolumns" title="" @cancel="yhdhshow=false" @confirm="yhdhconfirm"
			keyName="name"></u-picker>
		<u-picker :show="gwshow" :columns="gwcolumns" title="" @cancel="gwshow=false" @confirm="gwconfirm"
			keyName="name"></u-picker>
		<u-picker :show="htshow" :columns="htcolumns" title="" @cancel="htshow=false" @confirm="htconfirm"
			keyName="name"></u-picker>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				name: "",
				tel:"",
				idcard: "",
				address: "",
				htcompany_id: "",
				htcompany_name: "",
				gw_name:"",
				gangwei_id:"",
				company_id: "",
				company_name: "",
				user_gb_xz_id: "",
				user_gb_xz_name: "",
				yhdhcolumns: [],
				yhdhshow: false,
				xzcolumns: [],
				xzshow: false,
				gwcolumns: [],
				gwshow: false,
				htcolumns: [],
				htshow: false,
				config: {},
				checked: false,
				sex: 1,
				issubmit:false
			}
		},
		onLoad(options) {
			this.user_gb_xz_id = options.id
			this.user_gb_xz_name = options.name
			// this.getConfigInfo()
			this.getyhdh()
			this.getgw()
			this.getht()
			// this.getxz()
		},
		methods: {
			chaxun(){
				if (this.idcard == "") {
					httpRequest.toast("请输入身份证号")
					return false
				}
				httpRequest.request('/api/user/tgIdcardGetInfo', 'GET', {
					idcard:this.idcard
				}).then(res => {
					this.name = res.data.name
					this.sex = Number(res.data.sex)
					this.address = res.data.address
					this.tel = res.data.tel
				})
			},
			userAgreement(type) {
				uni.navigateTo({
					url: '/pages/login/xy?type=' + type
				})
			},
			getConfigInfo() {
				httpRequest.request('/api/index/getConfigInfo', 'GET', {}).then(res => {
					this.config = res.data
				})
			},
			getyhdh() {
				httpRequest.request('/api/user/companyIndex', 'GET', {}).then(res => {
					this.yhdhcolumns.push(res.data)
				})
			},
			yhdhconfirm(e) {
				this.company_name = e.value[0].name
				this.company_id = e.value[0].id
				this.yhdhshow = false
			},
			getht() {
				httpRequest.request('/api/user/htcompanyIndex', 'GET', {}).then(res => {
					this.htcolumns.push(res.data)
				})
			},
			htconfirm(e) {
				this.htcompany_id = e.value[0].id
				this.htcompany_name = e.value[0].name
				this.htshow = false
			},
			getgw() {
				httpRequest.request('/api/index/gangwei', 'GET', {}).then(res => {
					this.gwcolumns.push(res.data)
				})
			},
			gwconfirm(e) {
				this.gw_name = e.value[0].name
				this.gangwei_id = e.value[0].id
				this.gwshow = false
			},
			submit() {
				if(this.issubmit){
					return false
				}
				if (this.name == "") {
					httpRequest.toast("请输入姓名")
					return false
				}
				if(this.tel==""){
					httpRequest.toast("请输入手机号")
					return false
				}
				let phone = this.tel;
				if (!phone.match(/^1\d{10}$/)) {
					httpRequest.toast("请输入有效的手机号码");
					return false;
				}
				if (this.idcard == "") {
					httpRequest.toast("请输入身份证号")
					return false
				}
				if (this.address == "") {
					httpRequest.toast("请输入身份证居住地")
					return false
				}
				if (this.gangwei_id == "") {
					httpRequest.toast("请选择岗位")
					return false
				}
				if (this.htcompany_id == "") {
					httpRequest.toast("请选择合同公司")
					return false
				}
				if (this.company_id == "") {
					httpRequest.toast("请选择企业公司")
					return false
				}
				if (this.user_gb_xz_id == "") {
					httpRequest.toast("请选择险种")
					return false
				}
				if (this.checked == false) {
					httpRequest.toast("请仔细阅读并勾选")
					return false
				}
				this.issubmit = true
				let data = {
					name: this.name,
					idcard: this.idcard,
					sex:this.sex,
					address: this.address,
					company_id: this.company_id,
					htcompany_id: this.htcompany_id,
					gangwei_id: this.gangwei_id,
					user_gb_xz_id: this.user_gb_xz_id,
					tel:this.tel
				}
				let url = "/api/user/buyUserGb"
				httpRequest.request(url, 'GET', data).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						setTimeout(() => {
							uni.navigateBack({
								delta:2
							})
						}, 1000)
					}else{
						this.issubmit = false
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.colortext {
		color: $uni-color-primary;
	}

	.content {
		padding-bottom: 150rpx;
	}

	.noSelect {
		width: 138rpx;
		height: 69rpx;
		line-height: 69rpx;
		text-align: center;
		background: rgba(102, 102, 102, .1);
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		border: 2rpx solid rgba(102, 102, 102, .1);
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		margin-right: 30rpx;
		color: #666666;
	}

	.select {
		width: 138rpx;
		height: 69rpx;
		line-height: 69rpx;
		text-align: center;
		background: rgba(255, 133, 5, 0.1);
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		border: 2rpx solid #FF8505;
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FF8505;
		margin-right: 30rpx;
		position: relative;
	}

	.select::after {
		content: '';
		width: 25rpx;
		height: 20rpx;
		// background-image: url("/static/images/mine/invoice_select.png");
		background-size: 100% 100%;
		position: absolute;
		right: 0;
		bottom: 0;
	}

	.item_image_box {
		width: 33.33%;
	}

	.item_image {
		position: relative;
		width: 180rpx;
		height: 180rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}
</style>